package com.haochang.chunkvod.controller.fragment.hostess;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.haochang.base.BaseFragment;
import com.haochang.chunkvod.R;
import com.haochang.chunkvod.app.common.intent.IntentKey;

/**
 *         created at 2016/8/25 11:02
 *         房间管理页面
 */
public class RoomManagerFragment extends BaseFragment
{
	private String roomStatus = "";

	private RoomNoneFragment roomNoneFragment;
	private RoomUsingFragment roomUsingFragment;
	private RoomWaitFragment roomWaitFragment;

	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
	{
		View view = inflater.inflate(R.layout.fragment_room_manager, container, false);
		Bundle bundle = getArguments();
		roomStatus = bundle.getString(IntentKey.ROOM_STATUS);
		showViewByStatus();
		return view;
	}

	/**
	 * 根据状态显示不同布局
	 */
	public void showViewByStatus()
	{
		if (!TextUtils.isEmpty(roomStatus))
		{
			FragmentTransaction transaction = getFragmentManager().beginTransaction();
			Bundle bundle = getArguments();
			if (roomNoneFragment == null)
			{
				roomNoneFragment = new RoomNoneFragment();
			}
			roomNoneFragment.setArguments(bundle);

			if (roomUsingFragment == null)
			{
				roomUsingFragment = new RoomUsingFragment();
			}
			roomUsingFragment.setArguments(bundle);

			if (roomWaitFragment == null)
			{
				roomWaitFragment = new RoomWaitFragment();
			}
			roomWaitFragment.setArguments(bundle);

			if ("empty".equals(roomStatus))
			{
				//空房
				transaction.replace(R.id.room_manager_content, roomNoneFragment);
			} else if ("guiding".equals(roomStatus))
			{
				//带客
				transaction.replace(R.id.room_manager_content, roomWaitFragment);
			} else
			{
				//使用中
				transaction.replace(R.id.room_manager_content, roomUsingFragment);
			}
			transaction.addToBackStack(null);
			transaction.commit();
		}
	}

}
